package servlet;

import entity.Brand;
import entity.Vehiclecomplaints;
import service.impl.VehiclecomplaintsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author 吴阳基
 * @datetime 2024/01/04 15:12
 */

@WebServlet(urlPatterns = "/vehiclecomplaintsList")
public class VehiclecomplaintsListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");

        VehiclecomplaintsServiceImpl vehiclecomplaintsService = new VehiclecomplaintsServiceImpl();
        List<Vehiclecomplaints> vehiclecomplaintsList = null;

        Integer brandId = null;
        String brandIdParam = req.getParameter("brandId");
        if (brandIdParam != null && !brandIdParam.isEmpty()) {
            brandId = Integer.parseInt(brandIdParam);
        }

        vehiclecomplaintsList = vehiclecomplaintsService.VehiclecomplaintsList(brandId);

        List<Brand> brandList = vehiclecomplaintsService.brandList();

        req.setAttribute("vehiclecomplaintsList", vehiclecomplaintsList);
        req.setAttribute("brandList", brandList);

        req.getRequestDispatcher("list.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}